'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 生成奖励
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var rewardType = require('../consts/rewardType');
var dataApi = require('../libs/dataApi');
var randomUtil = require('../util/randomUtil');

/**
 * 生成奖励
 * @param  {[type]} equip_type [description]
 * @return {[type]}            [description]
 */
exports.generateReward = function (reward_conf) {
    if (reward_conf.reward_type == rewardType.RANDOM_EQUIP) {
        var goods_random_all_conf = dataApi.goods_random.findById(reward_conf.reward);
        reward_conf = randomUtil.sample(goods_random_all_conf);
    }

    return {
        reward_type: reward_conf.reward_type,
        reward: reward_conf.reward,
        reward_num: reward_conf.reward_num,
        reward_value: reward_conf.reward_value,
        hole_num: reward_conf.hole_num
    };
};

/**
 * 生成奖励列表
 * @param  {[type]} equip_type [description]
 * @return {[type]}            [description]
 */
exports.generateRewardList = function (reward_conf_list) {
    var self = this;
    var reward_list = [];
    _.each(reward_conf_list, function (reward_conf) {
        reward_list.push(self.generateReward(reward_conf));
    });
    return reward_list;
};

/**
 * 生成奖励
 * @param  {[type]} equip_type [description]
 * @return {[type]}            [description]
 */
exports.generateRewardVip = function (reward_conf) {
    if (reward_conf.reward_type == rewardType.RANDOM_EQUIP) {
        var goods_random_all_conf = dataApi.goods_random.findById(reward_conf.reward);
        reward_conf = randomUtil.sample(goods_random_all_conf);
    }

    return {
        reward_type: reward_conf.reward_type,
        reward: reward_conf.reward,
        reward_num: reward_conf.reward_num,
        reward_value: reward_conf.reward_value,
        hole_num: reward_conf.hole_num,
        vip_double: reward_conf.vip_double,
        vip_lv: reward_conf.vip_lvl
    };
};
